package com.ruoyi.erp.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.erp.domain.ProjectHourUser;
import com.ruoyi.erp.service.IProjectHourUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工时用户Controller
 * 
 * @author sauger
 * @date 2022-04-12
 */
@Controller
@RequestMapping("/erp/projectHourUser")
public class ProjectHourUserController extends BaseController
{
    private String prefix = "erp/projectHour/user";

    @Autowired
    private IProjectHourUserService projectHourUserService;

    @RequiresPermissions("erp:projectHourUser:view")
    @GetMapping()
    public String projectHourUser()
    {
        return prefix + "/projectHourUser";
    }

    /**
     * 查询工时用户列表
     */
    @RequiresPermissions("erp:projectHourUser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProjectHourUser projectHourUser)
    {
        startPage();
        List<ProjectHourUser> list = projectHourUserService.selectProjectHourUserList(projectHourUser);
        return getDataTable(list);
    }

    /**
     * 导出工时用户列表
     */
    @RequiresPermissions("erp:projectHourUser:export")
    @Log(title = "工时用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProjectHourUser projectHourUser)
    {
        List<ProjectHourUser> list = projectHourUserService.selectProjectHourUserList(projectHourUser);
        ExcelUtil<ProjectHourUser> util = new ExcelUtil<ProjectHourUser>(ProjectHourUser.class);
        return util.exportExcel(list, "工时用户数据");
    }

    /**
     * 新增工时用户
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存工时用户
     */
    @RequiresPermissions("erp:projectHourUser:add")
    @Log(title = "工时用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProjectHourUser projectHourUser)
    {
        return toAjax(projectHourUserService.insertProjectHourUser(projectHourUser));
    }

    /**
     * 修改工时用户
     */
    @RequiresPermissions("erp:projectHourUser:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        ProjectHourUser projectHourUser = projectHourUserService.selectProjectHourUserById(id);
        mmap.put("projectHourUser", projectHourUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存工时用户
     */
    @RequiresPermissions("erp:projectHourUser:edit")
    @Log(title = "工时用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProjectHourUser projectHourUser)
    {
        return toAjax(projectHourUserService.updateProjectHourUser(projectHourUser));
    }

    /**
     * 删除工时用户
     */
    @RequiresPermissions("erp:projectHourUser:remove")
    @Log(title = "工时用户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(projectHourUserService.deleteProjectHourUserByIds(ids));
    }
}
